<div class="fm-content">
  <div class="title">
    <i nz-icon [type]="'desktop'"></i>
    &nbsp;&nbsp;数据结构
  </div>
  <div class="clwork">
    <div class="top">
      <input nz-input placeholder="名称" class="fm-input first-input" [(ngModel)]="fs.queryObject['name:like']" />
      <input nz-input placeholder="别名" class="fm-input" [(ngModel)]="fs.queryObject['aliasName:like']" />
      <nz-button-group class="fm-search-input">
        <button nz-button nzType="primary" (click)="fs.loadData(true)">查询</button>
        <button nz-button (click)="fs.resetQueryObject() && fs.loadData(true)">重置</button>
      </nz-button-group>
      <div class="tool-right">
        <nz-button-group>
          <button nz-button [nzType]="'primary'" (click)="import()">导入</button>
          <button nz-button (click)="addRow()">新增</button>
          <button nz-button (click)="fs.editRow()">编辑</button>
          <button nz-popconfirm nzTitle="确认删除选择项?" (nzOnConfirm)="fs.delEntitys()" nzPlacement="bottomRight"
            nz-button>删除</button>
        </nz-button-group>
      </div>
    </div>

    <div class="left top-left">
      <nz-tree nzAsyncData (nzClick)="loadDataEx($event.node)" [nzData]="metadataDic.treeDatas">
      </nz-tree>
    </div>

    <div class="right top-right">
      <div class="table">
        <nz-table class="table" nzSize="middle" nzShowSizeChanger [nzPageSizeOptions]='[ 10, 15, 20, 30, 40, 50 ]'
          [nzFrontPagination]="false" [nzData]="fs.datas" [nzLoading]="fs.isLoading || fs.isDeleing"
          [nzTotal]="fs.rowsCount" [(nzPageIndex)]="fs.pageIndex" [(nzPageSize)]="fs.pageSize"
          (nzPageIndexChange)="fs.loadData()" (nzPageSizeChange)="fs.loadData(true)">
          <thead (nzSortChange)="fs.sort($event)" nzSingleSort>
            <tr>
              <th nzShowCheckbox [(nzChecked)]="fs.allChecked" [nzIndeterminate]="fs.indeterminate"
                (nzCheckedChange)="fs.checkAll($event)"></th>
              <th>序号</th>
              <th>别名(名称)</th>
              <th>数据类型</th>
              <th>主键/自动/为空/显示</th>
              <th>字典域</th>
              <th>长度.精度</th>
              <th>默认值</th>
            </tr>
          </thead>
          <tbody>
            <tr *ngFor="let data of fs.datas">
              <td nzShowCheckbox [(nzChecked)]="data.checked" (nzCheckedChange)="fs.refreshCheckStatus()">
              </td>
              <td>{{data.order}}</td>
              <td><span (click)="fs.editRow(data)" class="form-edit">{{data.aliasName}}({{data.name}})</span></td>
              <td>{{data.dataTypeName}}</td>
              <td>
                {{data.key | boolReform}}/{{data.auto | boolReform}}/{{data.allowNull | boolReform}}/{{data.canShow | boolReform}}
              </td>
              <td>{{data.dictionaryName}}</td>
              <td>{{data.maxlen}}.{{data.decimaldigits}}</td>
              <td>{{data.defaultValue}}</td>
            </tr>
          </tbody>
        </nz-table>
      </div>
    </div>

    <nz-modal nzWidth='830' nzTitle="编辑" [nzMaskClosable]='false' [nzFooter]="null" [(nzVisible)]="fs.isEditVisible"
      (nzOnCancel)="fs.closeEdit()">
      <form nz-form [nzLayout]="'inline'">
        <div nz-row [nzGutter]="24">
          <div nz-col [nzSpan]="12">
            <nz-form-item>
              <nz-form-label nzRequired class="form-label">名称</nz-form-label>
              <nz-form-control class="form-control" [nzValidateStatus]="name.invalid?'error':'success'" nzHasFeedback>
                <input nz-input required [(ngModel)]="fs.er.name" id="name" name="name" #name="ngModel">
              </nz-form-control>
            </nz-form-item>
          </div>
          <div nz-col [nzSpan]="12">
            <nz-form-item>
              <nz-form-label nzRequired class="form-label">别名</nz-form-label>
              <nz-form-control class="form-control" [nzValidateStatus]="aliasName.invalid?'error':'success'"
                nzHasFeedback>
                <input nz-input required [(ngModel)]="fs.er.aliasName" id="aliasName" name="aliasName"
                  #aliasName="ngModel">
              </nz-form-control>
            </nz-form-item>
          </div>
        </div>
        <div nz-row [nzGutter]="24">
          <div nz-col [nzSpan]="12">
            <nz-form-item>
              <nz-form-label nzRequired class="form-label">类型</nz-form-label>
              <nz-form-control class="form-control" [nzValidateStatus]="dataType.invalid?'error':'success'"
                nzHasFeedback>
                <nz-select [(ngModel)]="fs.er.dataType" (nzOpenChange)="dataTypeDic.load('0')" name="dataType" required
                  #dataType="ngModel" [nzPlaceHolder]="'请选择'">
                  <nz-option *ngFor="let option of dataTypeDic.datas" [nzLabel]="option.display" [nzValue]="option.id">
                  </nz-option>
                  <nz-option *ngIf="dataTypeDic.isLoading" nzDisabled nzCustomContent>
                    <i nz-icon type="loading" class="loading-icon"></i>加载中...
                  </nz-option>
                  <span *ngIf="!dataTypeDic.isLoaded">
                    <nz-option [nzLabel]="fs.er.dataTypeName" [nzValue]="fs.er.dataType">
                    </nz-option>
                  </span>
                </nz-select>
              </nz-form-control>
            </nz-form-item>
          </div>
          <div nz-col [nzSpan]="12">
            <nz-form-item>
              <nz-form-label class="form-label">属性</nz-form-label>
              <nz-form-control class="form-control">
                <label nz-checkbox [(ngModel)]="fs.er.key" name="key">主键</label>
                <label nz-checkbox [(ngModel)]="fs.er.auto" name="auto">自增</label>
                <!-- <label nz-checkbox [(ngModel)]="fs.er.allowNull"
                                        name="allowNull">可空</label> -->
              </nz-form-control>
            </nz-form-item>
          </div>
        </div>
        <div nz-row [nzGutter]="24">
          <div nz-col [nzSpan]="12">
            <nz-form-item>
              <nz-form-label class="form-label">长度</nz-form-label>
              <nz-form-control class="form-control">
                <nz-input-number [(ngModel)]="fs.er.maxlen" name="maxlen" [nzMin]="1" [nzMax]="1000" [nzStep]="1"
                  class="form-control">
                </nz-input-number>
              </nz-form-control>
            </nz-form-item>
          </div>
          <div nz-col [nzSpan]="12">
            <nz-form-item>
              <nz-form-label class="form-label">精度</nz-form-label>
              <nz-form-control class="form-control">
                <nz-input-number [(ngModel)]="fs.er.decimaldigits" [nzMin]="1" [nzMax]="10" [nzStep]="1"
                  name="decimaldigits" class="form-control">
                </nz-input-number>
              </nz-form-control>
            </nz-form-item>
          </div>
        </div>
        <div nz-row [nzGutter]="24">
          <div nz-col [nzSpan]="12">
            <nz-form-item>
              <nz-form-label class="form-label">字典域</nz-form-label>
              <nz-form-control class="form-control" nzHasFeedback>
                <input nz-input required [(ngModel)]="fs.er.dictionaryName" name="dictionaryName" />
              </nz-form-control>
            </nz-form-item>
          </div>
          <div nz-col [nzSpan]="12">
            <nz-form-item>
              <nz-form-label class="form-label">默认值</nz-form-label>
              <nz-form-control class="form-control" nzHasFeedback>
                <input nz-input [(ngModel)]="fs.er.defaultValue" name="defaultValue" />
              </nz-form-control>
            </nz-form-item>
          </div>
        </div>
        <div nz-row [nzGutter]="24">
          <div nz-col [nzSpan]="12">
            <nz-form-item>
              <nz-form-label class="form-label">所在分组</nz-form-label>
              <nz-form-control class="form-control" nzHasFeedback>
                <input nz-input [(ngModel)]="fs.er.group" name="group" />
              </nz-form-control>
            </nz-form-item>
          </div>
          <div nz-col [nzSpan]="12">
            <nz-form-item>
              <nz-form-label class="form-label">字典数据对应上级id</nz-form-label>
              <nz-form-control class="form-control" nzHasFeedback>
                <input nz-input [(ngModel)]="fs.er.dictionaryDataPid" name="dictionaryDataPid" />
              </nz-form-control>
            </nz-form-item>
          </div>
        </div>
        <div nz-row [nzGutter]="24">
          <div nz-col [nzSpan]="12">
            <nz-form-item>
              <nz-form-label nzRequired class="form-label">序号</nz-form-label>
              <nz-form-control class="form-control" [nzValidateStatus]="order.invalid?'error':'success'">
                <nz-input-number required [(ngModel)]="fs.er.order" name="order" [nzMin]="1" #order="ngModel"
                  [nzMax]="100" [nzStep]="1" class="form-control">
                </nz-input-number>
              </nz-form-control>
            </nz-form-item>
          </div>
          <div nz-col [nzSpan]="12">
            <nz-form-item>
              <nz-form-label class="form-label">其它</nz-form-label>
              <nz-form-control class="form-control">
                <label nz-checkbox [(ngModel)]="fs.er.canShow" name="canShow">显示</label>
              </nz-form-control>
            </nz-form-item>
          </div>
        </div>
        <div nz-row [nzGutter]="24">
          <div nz-col [nzSpan]="24" class="form-button-align">
            <button nz-button nzType="default" (click)="fs.closeEdit()" class="form-button">取消</button>
            <button nz-button nzType="primary"
              [disabled]='name.invalid || aliasName.invalid || dataType.invalid || order.invalid' (click)="fs.save()"
              [nzLoading]="fs.isSaveing">保存</button>
          </div>
        </div>
      </form>
    </nz-modal>

    <nz-modal nzWidth='415' nzTitle="导入" [nzMaskClosable]='false' [nzFooter]="null" [(nzVisible)]="regfs.isEditVisible"
      (nzOnCancel)="regfs.closeEdit()">
      <form nz-form [nzLayout]="'inline'">
        <div nz-row [nzGutter]="24">
          <div nz-col [nzSpan]="24">
            <nz-form-item>
              <nz-form-label class="form-label">本地库</nz-form-label>
              <nz-form-control class="form-control">
                <nz-switch nzCheckedChildren="是" nzUnCheckedChildren="否" [(ngModel)]="local" name="local">
                </nz-switch>
              </nz-form-control>
            </nz-form-item>
          </div>
        </div>
        <div nz-row [nzGutter]="24" *ngIf="!local">
          <div nz-col [nzSpan]="24">
            <nz-form-item>
              <nz-form-label class="form-label">驱动</nz-form-label>
              <nz-form-control class="form-control">
                <input nz-input [(ngModel)]="regfs.er.driver" name="driver">
              </nz-form-control>
            </nz-form-item>
          </div>
        </div>
        <div nz-row [nzGutter]="24" *ngIf="!local">
          <div nz-col [nzSpan]="24">
            <nz-form-item>
              <nz-form-label class="form-label">url</nz-form-label>
              <nz-form-control class="form-control">
                <input nz-input [(ngModel)]="regfs.er.url" name="url">
              </nz-form-control>
            </nz-form-item>
          </div>
        </div>
        <div nz-row [nzGutter]="24" *ngIf="!local">
          <div nz-col [nzSpan]="24">
            <nz-form-item>
              <nz-form-label class="form-label">用户名</nz-form-label>
              <nz-form-control class="form-control">
                <input nz-input [(ngModel)]="regfs.er.username" name="username">
              </nz-form-control>
            </nz-form-item>
          </div>
        </div>
        <div nz-row [nzGutter]="24" *ngIf="!local">
          <div nz-col [nzSpan]="24">
            <nz-form-item>
              <nz-form-label class="form-label">密码</nz-form-label>
              <nz-form-control class="form-control">
                <input nz-input [(ngModel)]="regfs.er.password" name="password">
              </nz-form-control>
            </nz-form-item>
          </div>
        </div>
        <div nz-row [nzGutter]="24">
          <div nz-col [nzSpan]="24">
            <nz-form-item>
              <nz-form-label nzRequired class="form-label">表名</nz-form-label>
              <nz-form-control class="form-control" [nzValidateStatus]="tableName.invalid?'error':'success'"
                nzHasFeedback>
                <input nz-input required [(ngModel)]="regfs.er.tableName" name="tableName" #tableName="ngModel">
              </nz-form-control>
            </nz-form-item>
          </div>
        </div>
        <div nz-row [nzGutter]="24">
          <div nz-col [nzSpan]="24" class="form-button-align">
            <button nz-button nzType="default" (click)="regfs.closeEdit()" class="form-button">取消</button>
            <button nz-button nzType="primary" [disabled]='tableName.invalid' (click)="reg()"
              [nzLoading]="regfs.isSaveing">保存</button>
          </div>
        </div>
      </form>
    </nz-modal>
  </div>
</div>